
package com.wobaby.util.xml;


public class XMLUtils
{

    public XMLUtils()
    {
    }

    public static boolean isLegalXMLChar(char ch)
    {
        if(ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')
            return false;
        if(ch == '\uFFFE' || ch == '\uFFFF')
            return false;
        return ch <= '\uD7FF' || ch >= '\uE000';
    }

    public static String filterIllegalChars(String source)
    {
        if(source == null)
            return source;
        StringBuffer sb = new StringBuffer(source.length());
        for(int i = 0; i < source.length(); i++)
        {
            char ch = source.charAt(i);
            if(isLegalXMLChar(ch))
                sb.append(ch);
        }

        return sb.toString();
    }
}